﻿
//=======================================================================
// <copyright file="Status.cs" company="Samuel Chen Studio">
//     Copyright (c) Samuel Chen Studio. All rights reserved.
//     author   : Samuel Chen
//     version  : 1.0
//     contact  : http://www.SamuelChen.net, samuel.net@gmail.com
// </copyright>
//=======================================================================

using System;
using System.Xml;
using System.Reflection;
using System.Diagnostics;

namespace Net.SamuelChen.SharpTweet {
    public class Status : TwitterObject {
        public DateTime created_at = DateTime.MinValue;
        public string id = string.Empty;
        public string text = string.Empty;
        public string source = string.Empty;
        public bool favorited = false;
        public string in_replay_to_status_id = string.Empty;
        public string in_replay_to_user_id = string.Empty;
        public string in_replay_to_screen_name = string.Empty;
        public Profile user = null;

        // TODO: refactor to APIUtility.cs
        public static Status FromXml(string content) {
            Status s = new Status();
            try {
                s.ParseXml(content);
            } catch (Exception ex) {
                Trace.TraceWarning(ex.ToString());
#if DEBUG
                throw ex;
#endif
            }
            return s;
        }

        protected override object ParseUnknownTypeXML(XmlNode node, Type tagetType) {
            if (null == node)
                return null;

            string name = node.Name;    // property name
            if (string.Compare(name, "user", true) == 0) {
                Profile p = Profile.FromXml(node.OuterXml);
                return p;
            } else
                return base.ParseUnknownTypeXML(node, tagetType);
        }

        // TODO: refactor to APIUtility.cs
        internal static Status FromJson(string content) {
            throw new NotImplementedException();
        }

     }
}